<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="getBtn">get</button>

  <script>
    let getBtn = document.getElementById('getBtn')

    getBtn.onclick = function() {
      // 发请求
      // 1. 创建实例
      let xhr = new XMLHttpRequest()  

      // 2. 先open 再send
      xhr.open('GET', 'http://www.liulongbin.top:3006/api/getbooks')
      xhr.send()

      // 3. 请求结束 获取数据
      xhr.onreadystatechange = function() {
        if(xhr.readyState === 4 && xhr.status === 200) {
          console.log( JSON.parse(xhr.responseText) )  // 4. 当请求成功， 打印相应结果
        }
      }
    }
  </script>
</body>
</html>